// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie;

import java.util.ArrayList;
import zombie.characters.IsoZombie;
import zombie.debug.DebugLog;
import zombie.debug.DebugType;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoWorld;
import zombie.iso.objects.IsoDeadBody;
import zombie.util.Type;

public final class MovingObjectUpdateSchedulerUpdateBucket {
    public int frameMod;
    ArrayList<IsoMovingObject>[] buckets;

    public MovingObjectUpdateSchedulerUpdateBucket(int mod) {
        this.init(mod);
    }

    public void init(int _frameMod) {
        this.frameMod = _frameMod;
        this.buckets = new ArrayList[_frameMod];

        for (int _int = 0; _int < this.buckets.length; _int++) {
            this.buckets[_int] = new ArrayList();
        }
    }

    public void clear() {
        for (int _int = 0; _int < this.buckets.length; _int++) {
            ArrayList arrayList = this.buckets[_int];
            arrayList.clear();
        }
    }

    public void remove(IsoMovingObject obj) {
        for (int _int = 0; _int < this.buckets.length; _int++) {
            ArrayList arrayList = this.buckets[_int];
            arrayList.remove(obj);
        }
    }

    public void add(IsoMovingObject o) {
        int _int = o.getID() % this.frameMod;
        this.buckets[_int].add(o);
    }

    public void update(int frameCounter) {
        zombie.GameTime.getInstance().PerObjectMultiplier = (float)this.frameMod;
        ArrayList arrayList = this.buckets[frameCounter % this.frameMod];

        for (int _int = 0; _int < arrayList.size(); _int++) {
            IsoMovingObject isoMovingObject = (IsoMovingObject)arrayList.get(_int);
            if (isoMovingObject instanceof IsoDeadBody) {
                IsoWorld.instance.getCell().getRemoveList().add(isoMovingObject);
            } else {
                IsoZombie isoZombie = Type.tryCastTo(isoMovingObject, IsoZombie.class);
                if (isoZombie != null && zombie.VirtualZombieManager.instance.isReused(isoZombie)) {
                    DebugLog.log(DebugType.Zombie, "REUSABLE ZOMBIE IN MovingObjectUpdateSchedulerUpdateBucket IGNORED " + isoMovingObject);
                } else {
                    isoMovingObject.preupdate();
                    isoMovingObject.update();
                }
            }
        }

        zombie.GameTime.getInstance().PerObjectMultiplier = 1.0F;
    }

    public void postupdate(int frameCounter) {
        zombie.GameTime.getInstance().PerObjectMultiplier = (float)this.frameMod;
        ArrayList arrayList = this.buckets[frameCounter % this.frameMod];

        for (int _int = 0; _int < arrayList.size(); _int++) {
            IsoMovingObject isoMovingObject = (IsoMovingObject)arrayList.get(_int);
            IsoZombie isoZombie = Type.tryCastTo(isoMovingObject, IsoZombie.class);
            if (isoZombie != null && zombie.VirtualZombieManager.instance.isReused(isoZombie)) {
                DebugLog.log(DebugType.Zombie, "REUSABLE ZOMBIE IN MovingObjectUpdateSchedulerUpdateBucket IGNORED " + isoMovingObject);
            } else {
                isoMovingObject.postupdate();
            }
        }

        zombie.GameTime.getInstance().PerObjectMultiplier = 1.0F;
    }

    public void removeObject(IsoMovingObject object) {
        for (int _int = 0; _int < this.buckets.length; _int++) {
            ArrayList arrayList = this.buckets[_int];
            arrayList.remove(object);
        }
    }

    public ArrayList<IsoMovingObject> getBucket(int frameCounter) {
        return this.buckets[frameCounter % this.frameMod];
    }
}
